package insight;

import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

/**
 * @author huu
 * @create 2025-08-25-11:17
 */
public class WeatherStation {

//    //添加订阅信息
//    private Set<User> users = new HashSet<>();
//    public void subscribe(User user){
//        users.add(user);
//    }


    //获取天气信息
    public String getInfo(){
        if(new Random().nextBoolean()){
            return "晴天";
        }else{
            return "阴天";
        }
    }

    //传入TV这个总线
    private TVStation tvStation;
    public WeatherStation(TVStation tvStation) {
        this.tvStation = tvStation;
    }

    public void start() throws InterruptedException {
        while(true){
            String info = getInfo();
//            //循环发送信息给订阅者
//            for (User user : users) {
//                user.reciveinfo(info);
//            }
            //将info包装成天气更新事件后发布
            new WeatherUpdateEvent(info);
            tvStation.publishEvent(new WeatherUpdateEvent(info));
            //tvStation.onInfoUpdate(info);
            Thread.sleep(3000);
        }
    }


}
